<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("comctrls.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Set_Template_Recurring_Edit extends Page
{
       public $JTJavaScript10 = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $edDescTemp = null;
       public $cmbSchedChange = null;
       public $COMPLETION_TYPE = null;
       public $lblBeforeDue = null;
       public $cmbDaysMonthsReminder = null;
       public $edRemind = null;
       public $Label7 = null;
       public $checkRecurring = null;
       public $lblDueUnit = null;
       public $edDue = null;
       public $lblDueEveryUnit = null;
       public $cmbDaysMonthsEvery = null;
       public $edDueEvery = null;
       public $lblDueEvery = null;
       public $lblDue = null;
       public $cmbSchedule = null;
       public $Label1 = null;
       public $dpBasis = null;
       public $Label5 = null;
       public $JTDivDesc = null;
       public $JTGroupBox2 = null;
       public $btnAddDesc = null;
       public $btnDelDesc = null;
       public $edDesc = null;
       public $listDesc = null;
       public $JTDivType = null;
       public $JTGroupBox1 = null;
       public $btnAddType = null;
       public $btnDelType = null;
       public $edType = null;
       public $listType = null;
       public $btnCancel = null;
       public $btnUpdate = null;
       public $btnShowType = null;
       public $btnShowDescription = null;
       public $cmbcompletion = null;
       public $Label3 = null;
       public $edOthers = null;
       public $lblOther = null;
       public $memoComments = null;
       public $lblComments = null;
       public $cmbVendor = null;
       public $Label2 = null;
       public $edPrice = null;
       public $lblFixedPrice = null;
       public $cmbDesc = null;
       public $cmbType = null;
       public $lblType = null;
       public $JTJavaScript9 = null;
       public $JTJavaScript8 = null;
       public $JTJavaScript7 = null;
       public $compid = null;
       public $imgBack = null;
       public $JTSiteTheme1 = null;
       public $JTJavaScript6 = null;
       public $JTJavaScript5 = null;
       public $JTJavaScript4 = null;
       public $Image3 = null;
       public $hiddenStyle = null;
       public $hiddenTemplate = null;
       public $hiddenRecurring = null;
       function Set_Template_Recurring_EditJSLoad($sender, $params)
       {

       ?>
       cmbSchedChange();
       //completionWindow();
       return false;
       <?php

       }

       function checkRecurringJSChange($sender, $params)
       {

       ?>
       cmbSchedChange();
       return false;
       <?php

       }

       function cmbScheduleJSChange($sender, $params)
       {

       ?>
       var check = document.getElementById('checkRecurring');

       var schedObj = document.getElementById('cmbSchedule');
       var sched = schedObj.value;

       var lblDueObj = document.getElementById('lblDue');
       var lblDueOuterObj = document.getElementById('lblDue_outer');

       var edDueObj = document.getElementById('edDue');
       var edDueOuterObj = document.getElementById('edDue_outer');

       var lblDueUnitObj = document.getElementById('lblDueUnit');
       var lblDueUnitOuterObj = document.getElementById('lblDueUnit_outer');
       //dpBasisObj
          var dpBasisouterObj = document.getElementById('dpBasis_outer');
             var calendarFiled1Obj = document.getElementById('f-calendar-field-1');
             var calendarTrigger1Obj = document.getElementById('f-calendar-trigger-1');

       var lblDueEveryObj = document.getElementById('lblDueEvery');
       var lblDueEveryOuterObj = document.getElementById('lblDueEvery_outer');

       var edDueEveryObj = document.getElementById('edDueEvery');
       var edDueEveryOuterObj = document.getElementById('edDueEvery_outer');

       var lblDueEveryUnitObj = document.getElementById('lblDueEveryUnit');
       var lblDueEveryUnitOuterObj = document.getElementById('lblDueEveryUnit_outer');

       var cmbDaysMonthsEveryObj = document.getElementById('cmbDaysMonthsEvery');
       var cmbDaysMonthsEveryOuterObj = document.getElementById('cmbDaysMonthsEvery_outer');
       var remind = document.getElementById('edRemind');

       if(sched=='Mileage')
       {
        lblDueObj.innerHTML = 'Due at:';
        lblDueUnitObj.innerHTML = 'Km';
        lblDueEveryUnitObj.innerHTML = 'Km';

        edDueOuterObj.style.left = '155px';
        edDueObj.style.visibility = 'visible';

        lblDueUnitOuterObj.style.left = '315px';
        lblDueUnitObj.style.visibility = 'visible';

        dpBasisouterObj.style.left = '470px';
        calendarFiled1Obj.style.visibility = 'hidden';
        calendarTrigger1Obj.style.visibility = 'hidden';

        lblDueEveryUnitOuterObj.style.left = '521px';
        cmbDaysMonthsEveryOuterObj.style.left = '700px';
        if(check.checked==true)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'hidden';
        lblDueEveryUnitObj.style.visibility = 'visible';
        }
        if(check.checked==false)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'hidden';
        lblDueEveryUnitObj.style.visibility = 'hidden';
        }
        remind.style.width = '157px';
        lblDueEveryOuterObj.style.left = '358px';
        edDueEveryOuterObj.style.left = '417px';
        edDueEveryObj.style.width = '104px';

       }
       if(sched=='Hours')
       {
        lblDueObj.innerHTML = 'Due at:';
        lblDueUnitObj.innerHTML = 'Hours';
        lblDueEveryUnitObj.innerHTML = 'Hours';

        edDueOuterObj.style.left = '155px';
        edDueObj.style.visibility = 'visible';

        lblDueUnitOuterObj.style.left = '315px';
        lblDueUnitObj.style.visibility = 'visible';

        dpBasisouterObj.style.left = '470px';
        calendarFiled1Obj.style.visibility = 'hidden';
        calendarTrigger1Obj.style.visibility = 'hidden';

        lblDueEveryUnitOuterObj.style.left = '521px';
        cmbDaysMonthsEveryOuterObj.style.left = '700px';
        if(check.checked==true)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'hidden';
        lblDueEveryUnitObj.style.visibility = 'visible';
        }
        if(check.checked==false)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'hidden';
        lblDueEveryUnitObj.style.visibility = 'hidden';
        }
        remind.style.width = '157px';
        lblDueEveryOuterObj.style.left = '358px';
        edDueEveryOuterObj.style.left = '417px';
        edDueEveryObj.style.width = '104px';
       }
       if(sched=='Time')
       {
        lblDueObj.innerHTML = 'Due date:';

        edDueOuterObj.style.left = '562px';
        edDueObj.style.visibility = 'hidden';
        lblDueUnitOuterObj.style.left = '684px';
        lblDueUnitObj.style.visibility = 'hidden';

        dpBasisouterObj.style.left = '155px';
        calendarFiled1Obj.style.visibility = 'visible';
        calendarTrigger1Obj.style.visibility = 'visible';

        lblDueEveryUnitOuterObj.style.left = '700px';
        cmbDaysMonthsEveryOuterObj.style.left = '470px';
        if(check.checked==true)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'visible';
        lblDueEveryUnitObj.style.visibility = 'hidden';
        }
        if(check.checked==false)
        {
        cmbDaysMonthsEveryObj.style.visibility = 'hidden';
        lblDueEveryUnitObj.style.visibility = 'hidden';
        }
        remind.style.width = '68px';
        lblDueEveryOuterObj.style.left = '328px';
        edDueEveryOuterObj.style.left = '389px';
        edDueEveryObj.style.width = '78px';
       }

       if(check.checked==true)
       {
        lblDueEveryObj.style.visibility = 'visible';
        edDueEveryObj.style.visibility = 'visible';
       }
       if(check.checked==false)
       {
        lblDueEveryObj.style.visibility = 'hidden';
        edDueEveryObj.style.visibility = 'hidden';
       }

       //REMINDER ME
       var lblBeforeDueObj = document.getElementById('lblBeforeDue');
       var lblBeforeDueOuterObj = document.getElementById('lblBeforeDue_outer');

       var cmbDaysMonthsReminderObj = document.getElementById('cmbDaysMonthsReminder');
       var cmbDaysMonthsReminderOuterObj = document.getElementById('cmbDaysMonthsReminder_outer');
       if(sched=='Mileage' || sched=='Hours')
       {
        cmbDaysMonthsReminderOuterObj.style.left = '516px';
        cmbDaysMonthsReminderObj.style.visibility = 'hidden';
        lblBeforeDueOuterObj.style.left = '319px';
       }

       if(sched=='Mileage')
       {
       lblBeforeDueObj.innerHTML = 'Km before due';
       }
       if(sched=='Hours')
       {
       lblBeforeDueObj.innerHTML = 'Hours before due';
       }

       if(sched=='Time')
       {
        cmbDaysMonthsReminderOuterObj.style.left = '229px';
        cmbDaysMonthsReminderObj.style.visibility = 'visible';
        lblBeforeDueOuterObj.style.left = '319px';
        lblBeforeDueObj.innerHTML = 'before due date';
       }

       return false;
       <?php

       }



       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function btnDelDescJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var DescIndex = document.getElementById('listDesc').selectedIndex;
       var DescValue = document.getElementById('listDesc')[DescIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxDesc3(DescValue,comp);
       <?php

       }

       function btnAddDescJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var adddesc = document.getElementById('edDesc').value;
       var comp = document.getElementById('compid').value;
       AjaxDesc2(adddesc,comp);
       document.Template_Recurring_Edit.edDesc.value = "";
       <?php

       }

       function btnShowDescriptionJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivDesc').Show();
       document.Template_Recurring_Edit.edDesc.value = "";
       <?php

       }

       function btnDelTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var TypeIndex = document.getElementById('listType').selectedIndex;
       var TypeValue = document.getElementById('listType')[TypeIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxType3(TypeValue,comp);
       <?php

       }

       function btnAddTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addtype = document.getElementById('edType').value;
       var comp = document.getElementById('compid').value;
       AjaxType2(addtype,comp);
       document.getElementById('edType').value = "";
       <?php

       }

       function btnShowTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivType').Show();
       document.getElementById('edType').value = "";
       <?php

       }
       function cmbcompletionJSChange($sender, $params)
       {

       //echo $this->cmbcompletion->ajaxCall('CompletionChange');
       ?>
       cmbSchedChange();
       completionWindow();
       return false;
       <?php

       }


       function btnUpdateClick($sender, $params)
       {
       $time_save = null;
       $miles_save = null;
       $schedBy_save = null;
       /*if($this->cmbSchedule->getItemIndex()=='Time')
       {
       $time_save = $this->edDueEvery->Text;
       $schedBy_save = $this->cmbDaysMonths->getItemIndex();
       }
       if($this->cmbSchedule->getItemIndex()=='Both')
       {
       $miles_save = $this->edDueEvery->Text;
       $time_save = $this->edDueEvery2->Text;
       $schedBy_save = $this->cmbDaysMonths2->getItemIndex();
       }
       if($this->cmbSchedule->getItemIndex()=='Usage')
       {
       $miles_save = $this->edDueEvery->Text;
       }
       */
       if($this->cmbSchedule->getItemIndex()=='Time')
       {
       $time_save = $this->edDueEvery->Text;
       $schedBy_save = $this->cmbDaysMonthsEvery->getItemIndex();
       }
       if($this->cmbSchedule->getItemIndex()=='Mileage' || $this->cmbSchedule->getItemIndex()=='Hours')
       {
       $miles_save = $this->edDueEvery->Text;
       }

       //recurring
       if($this->cmbSchedule->getItemIndex()=='Time')
       {
       $val = $this->edDueEvery->Text;
       $days_mos = $this->cmbDaysMonthsEvery->getItemIndex();
       }

       /*if($this->cmbSchedule->getItemIndex()=='Both')
       {
       $val = $this->edDueEvery2->Text;
       $days_mos = $this->cmbDaysMonths2->getItemIndex();
       }*/


       $basis = $this->dpBasis->Text;

       if($this->cmbSchedule->getItemIndex()!='Mileage' && $this->cmbSchedule->getItemIndex()!='Hours')
       {

       if($days_mos=='Days')
       {
       $date = date($basis);
       $date_computed = strtotime(date("Y-m-d", strtotime($date)) . "+".$val." day");
       $due_date = date("Y-m-d", $date_computed);
       }

       if($days_mos=='Months')
       {
       $date = date($basis);
       $date_computed = strtotime(date("Y-m-d", strtotime($date)) . "+".$val." month");
       $due_date = date("Y-m-d", $date_computed);
       }

       }

       if($this->cmbSchedule->getItemIndex()=='Mileage' || $this->cmbSchedule->getItemIndex()=='Hours')
       {
         $save_rem = "rem_usage = '".$this->edRemind->Text."',";
       }
       if($this->cmbSchedule->getItemIndex()=='Time')
       {
         $save_rem = "rem_by = '".$this->cmbDaysMonthsReminder->getItemIndex()."',rem_time = '".$this->edRemind->Text."',";
       }
       if($this->checkRecurring->Checked == true)
       $recurring = '1';
       if($this->checkRecurring->Checked == false)
       $recurring = '0';

       mysql_query("update template_recurring_tbl set
       recurring = '".$recurring."',
       schedule_by = '".$this->cmbSchedule->getItemIndex()."',
       due_usage = '".$miles_save."',
       due_time = '".$time_save."',
       due_by = '".$schedBy_save."',
       usage_basis = '".$this->edDue->Text."',
       date_basis = '".$this->dpBasis->Text."',
       computed_date = '".$due_date."',
       ".$save_rem."
       completion_window = 'WorkOrder',
       type = '".$this->cmbType->getItemIndex()."',
       description = '".$this->edDescTemp->Text."',
       other_description = '".$this->edOthers->Text."',
       price = '".$this->edPrice->Text."',
       vendor = '".$this->cmbVendor->getItemIndex()."',
       comments = '".$this->memoComments->Text."'
       where template_id = '".$this->hiddenTemplate->getValue()."' and id = '".$this->hiddenRecurring->getValue()."'")or die ("UPDATE RECURRING-".mysql_error());

       redirect('set_template_recurring_list.php?template_id='.$this->hiddenTemplate->getValue().'&recurring='.$this->hiddenRecurring->getValue());
       }


       function btnCancelClick($sender, $params)
       {
       redirect('set_template_recurring_list.php?template_id='.$this->hiddenTemplate->getValue().'&recurring='.$this->hiddenRecurring->getValue());
       }


       function CompletionChange()
       {
       $completion = $this->cmbcompletion->getItemIndex();

       if($completion=="WorkOrder")
       {
        $this->cmbType->Clear();
        $result_type = mysql_query("select * from lookup_workorder_tbl where company_id = '".$_SESSION['company_id']."' AND category='type'");

          while($row_type = mysql_fetch_array($result_type))
          {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
          }

         //list type workorder
        $this->listType->Clear();
        $result_t = mysql_query("select * from lookup_workorder_tbl where company_id = '".$_SESSION['company_id']."' AND category='type'");

          while($row_t = mysql_fetch_array($result_t))
          {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
          }

       }


       if($completion=="Payment")
       {
        $this->cmbType->Clear();
        $result_type = mysql_query("select * from lookup_expense_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

          while($row_type = mysql_fetch_array($result_type))
          {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
          }
        //list type payment
        $this->listType->Clear();
        $result_t = mysql_query("select * from lookup_expense_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

          while($row_t = mysql_fetch_array($result_t))
          {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
          }


       }

       if($completion=="None")
       {
        $result_type = mysql_query("select * from lookup_expense_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

          while($row_type = mysql_fetch_array($result_type))
          {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
          }

        //list type none
        $this->listType->Clear();
        $result_t = mysql_query("select * from lookup_expense_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

          while($row_t = mysql_fetch_array($result_t))
          {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
          }

       }


       }

       function Set_Template_Recurring_EditCreate($sender, $params)
       {
       $this->compid->Value = $_SESSION['company_id'];
       $template = $_GET['template_id'];
       $recurring_id = $_GET['recurring'];
       //$style = $_GET['style'];
       $this->hiddenTemplate->setValue($template);
       $this->hiddenRecurring->setValue($recurring_id);
       //$this->hiddenStyle->setValue($style);

       $query_recurring = "select * from template_recurring_tbl where template_id = '".$this->hiddenTemplate->getValue()."' and id='".$this->hiddenRecurring->getValue()."'";
       $result_recurring_show = mysql_query($query_recurring)or die("SELECT RECURRING - " . mysql_error());
       $row_recurring = mysql_fetch_array($result_recurring_show);

       $sched_by = $row_recurring['schedule_by'];

       $this->edOthers->Text=$row_recurring['other_description'];
       $this->edPrice->Text=$row_recurring['price'];
       $this->memoComments->Text=$row_recurring['comments'];
       $this->edDescTemp->Text=$row_recurring['description'];
       $this->edDue->Text=$row_recurring['usage_basis'];
       $this->dpBasis->Text=$row_recurring['date_basis'];

       if($sched_by=='Mileage' || $sched_by=='Hours')
       {
       $this->edRemind->Text = $row_recurring['rem_usage'];
       $this->edDueEvery->Text = $row_recurring['due_usage'];
       }

       if($sched_by=='Date' || $sched_by=='Time')
       {
       $this->edRemind->Text = $row_recurring['rem_time'];
       $this->edDueEvery->Text = $row_recurring['due_time'];
       }


       $this->cmbcompletion->ItemIndex=$row_recurring['completion_window'];;
       $this->cmbVendor->ItemIndex=$row_recurring['vendor'];
       $sched = $this->cmbSchedule->ItemIndex=$row_recurring['schedule_by'];


       $recurring = $row_recurring['recurring'];

       if($recurring=='0')
       $this->checkRecurring->Checked = false;

       if($recurring=='1')
       $this->checkRecurring->Checked = true;


       /*if($sched=='Time')
       {
       $this->lblMilesHours->Visible=false;
       $this->cmbDaysMonths->Visible=true;
       $this->cmbDaysMonths->ItemIndex=$row_recurring['due_by'];
       $this->edDueEvery->Visible=true;
       $this->edDueEvery->Text=$row_recurring['due_time'];
       $this->lblOr->Visible=false;
       $this->edDueEvery2->Visible=false;
       $this->cmbDaysMonths2->Visible=false;
       $this->dpBasis->Visible=true;
       $this->dpBasis->Text=$row_recurring['date_basis'];
       $this->lblfrm->Visible=true;
       //$this->dpBasis->Left=422;
       //$this->lblfrm->Left=382;
        $this->dpBasis->Left=445;
       $this->lblfrm->Left=409;
       $this->lblhours->Visible=false;
       }
       else if ($sched=='Both')
       {
       $this->cmbDaysMonths->Visible=false;
       $this->edDueEvery2->Visible=true;
       $this->edDueEvery2->Text=$row_recurring['due_time'];
       $this->cmbDaysMonths2->Visible=true;
       $this->cmbDaysMonths2->ItemIndex=$row_recurring['due_by'];
       $this->lblMilesHours->Visible=true;
       $this->lblOr->Visible=true;
       $this->edDueEvery->Text=$row_recurring['due_usage'];
       $this->dpBasis->Visible=true;
       $this->dpBasis->Text=$row_recurring['date_basis'];
       $this->dpBasis->Left=612;
       $this->lblfrm->Visible=true;
       $this->lblfrm->Left=570;
       $this->lblhours->Visible=false;
       }
       else if ($sched=='Usage')
       {
       $this->edDueEvery2->Visible=false;
       $this->cmbDaysMonths2->Visible=false;
       $this->cmbDaysMonths->Visible=false;
       $this->lblMilesHours->Visible=true;
       $this->lblOr->Visible=false;
       $this->edDueEvery->Visible=true;
       $this->edDueEvery->Text=$row_recurring['due_usage'];
       $this->lblfrm->Visible=false;
       $this->dpBasis->Visible=false;
       $this->lblhours->Visible=false;
       }
       else if ($sched=='Hours')
       {
       $this->edDueEvery2->Visible=false;
       $this->cmbDaysMonths2->Visible=false;
       $this->cmbDaysMonths->Visible=false;
       $this->lblMilesHours->Visible=false;
       $this->lblOr->Visible=false;
       $this->edDueEvery->Visible=true;
       $this->edDueEvery->Text=$row_recurring['due_usage'];
       $this->lblfrm->Visible=false;
       $this->dpBasis->Visible=false;
       $this->lblhours->Visible=true;
       }
       */


       //$this->cmbType->Clear();
       /*$this->cmbType->ItemIndex=$row_recurring['type'];
       $result_type = mysql_query("select * from lookup_workorder_tbl where company_id='".$_SESSION['company_id']."' AND category='type'");

        while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
        }

        //list type
       $result_t = mysql_query("select * from lookup_workorder_tbl where company_id = '".$_SESSION['company_id']."' AND category='type'");

        while($row_t = mysql_fetch_array($result_t))
        {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
        }*/

       $this->cmbDesc->Clear();
       $this->cmbDesc->ItemIndex=$row_recurring['description'];
       $result_desc = mysql_query("select * from lookup_workorder_tbl where company_id='".$_SESSION['company_id']."' AND category='task descriptions'");

        while($row_desc = mysql_fetch_array($result_desc))
        {
            $this->cmbDesc->AddItem($row_desc['value'], null, $row_desc['value']);
        }

         // list description
         $this->listDesc->Clear();
         $result_d = mysql_query("select * from lookup_workorder_tbl where company_id = '".$_SESSION['company_id']."' AND category='task descriptions'");

        while($row_d = mysql_fetch_array($result_d))
        {
            $this->listDesc->AddItem($row_d['value'], null, $row_d['value']);
        }

        $this->cmbType->Clear();
        $this->cmbType->setItemIndex($row_recurring['type']);
        $this->cmbType->AddItem('--Select--', null, '--Select--');
        $result_type = mysql_query("select * from lookup_reminder_tbl where company_id='".$_SESSION['company_id']."' AND category='type'");

        while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
        }

         //list type
       $result_t = mysql_query("select * from lookup_reminder_tbl where company_id = '".$_SESSION['company_id']."' AND category='type'");

        while($row_t = mysql_fetch_array($result_t))
        {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
        }
        //$this->cmbType->setItems($row_recurring['type']);


       $this->cmbVendor->Clear();
       $this->cmbVendor->AddItem('--Select--',null,'--Select--');
       $this->cmbVendor->ItemIndex=$row_recurring['vendor'];
       $result_vendor = mysql_query("select vendor_name from vendor_tbl where company_id='".$_SESSION['company_id']."'");

        while($row_vendor = mysql_fetch_array($result_vendor))
        {
            $this->cmbVendor->AddItem($row_vendor['vendor_name'], null, $row_vendor['vendor_name']);
        }

       $this->imgBack->setLink('template_recurring_list.php?template_id='.$this->hiddenTemplate->getValue().'&recurring='.$this->hiddenRecurring->getValue());

       /*echo "<script type=text/javascript>
       cmbSchedChange();
       </script>";*/
       }

       function cmbScheduleChange($sender, $params)
       {
       $schedule = $this->cmbSchedule->getItemIndex();

       if($schedule=='Time')
       {
       $this->edDueEvery2->Visible=false;
       $this->cmbDaysMonths2->Visible=false;
       $this->lblMilesHours->Visible=false;
       $this->lblOr->Visible=false;
       $this->cmbDaysMonths->Visible=true;
       $this->edDueEvery->Visible=true;
       $this->dpBasis->Visible=true;
       $this->dpBasis->Left=445;
       $this->lblfrm->Left=409;
       $this->lblfrm->Visible=true;
       $this->lblhours->Visible=false;

       }
       else if ($schedule=='Both')
       {
       $this->cmbDaysMonths->Visible=false;
       $this->edDueEvery2->Visible=true;
       $this->cmbDaysMonths2->Visible=true;
       $this->lblMilesHours->Visible=true;
       $this->lblOr->Visible=true;
       $this->dpBasis->Visible=true;
       $this->dpBasis->Left=612;
       $this->lblfrm->Visible=true;
       $this->lblfrm->Left=570;
       }
       else if ($schedule=='Usage')
       {
       $this->edDueEvery->Visible=true;
       $this->lblMilesHours->Visible=true;
       $this->edDueEvery2->Visible=false;
       $this->cmbDaysMonths2->Visible=false;
       $this->cmbDaysMonths->Visible=false;
       $this->lblOr->Visible=false;
       $this->dpBasis->Visible=false;
       $this->lblfrm->Visible=false;
       $this->lblhours->Visible=false;
       }
       else if ($schedule=='Hours')
       {
       $this->edDueEvery->Visible=true;
       $this->lblMilesHours->Visible=false;
       $this->edDueEvery2->Visible=false;
       $this->cmbDaysMonths2->Visible=false;
       $this->cmbDaysMonths->Visible=false;
       $this->lblOr->Visible=false;
       $this->dpBasis->Visible=false;
       $this->lblfrm->Visible=false;
       $this->lblhours->Visible=true;
       }


       }

}

global $application;

global $Set_Template_Recurring_Edit;

//Creates the form
$Set_Template_Recurring_Edit=new Set_Template_Recurring_Edit($application);

//Read from resource file
$Set_Template_Recurring_Edit->loadResource(__FILE__);

//Shows the form
$Set_Template_Recurring_Edit->show();

?>